/*
 * Copyright (c) 2011 Ball State University
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package edu.bsu.android.gtv.apps.bconnected.objects;

/**
 * Term object
 * @author Kyle Parker, University Computing Services
 */
public class Term implements Comparable<Term> {
	private String endDate;
	private String shortAcademicYear;
	private String shortTermFullDesc;
	private String startDate;
	private String termNumber;
	private String termID;
	private String termFullDesc;
    
	public String getEndDate() {		
		return endDate;
	}
	public void setEndDate(String value)  {
		this.endDate = value.trim();
	}

	public String getShortAcademicYear() {		
		return shortAcademicYear;
	}
	public void setShortAcademicYear(String value) {
		this.shortAcademicYear = value.trim();
	}

	public String getShortTermFullDesc() {		
		return shortTermFullDesc;
	}
	public void setShortTermFullDesc(String value) {
		this.shortTermFullDesc = value.trim();
	}

	public String getStartDate() {		
		return startDate;
	}
	public void setStartDate(String value) {
		this.startDate = value.trim();
	}

	public String getTermNumber() {		
		return termNumber;
	}
	public void setTermNumber(String value) {
		this.termNumber = value.trim();
	}

	public String getTermID() {		
		return termID;
	}
	public void setTermID(String value) {
		this.termID = value.trim();
	}

	public String getTermFullDesc() {		
		return termFullDesc;
	}
	public void setTermFullDesc(String value) {
		this.termFullDesc = value.trim();
	}
	
	public Term copy() {
		Term copy = new Term();
		copy.endDate = endDate;
		copy.shortAcademicYear = shortAcademicYear;
		copy.shortTermFullDesc = shortTermFullDesc;
		copy.startDate = startDate;
		copy.termNumber = termNumber;
		copy.termID = termID;
		copy.termFullDesc = termFullDesc;
		return copy;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;

		result = prime * result + ((endDate == null) ? 0 : endDate.hashCode());
		result = prime * result + ((shortAcademicYear == null) ? 0 : shortAcademicYear.hashCode());
		result = prime * result + ((shortTermFullDesc == null) ? 0 : shortTermFullDesc.hashCode());
		result = prime * result + ((startDate == null) ? 0 : startDate.hashCode());
		result = prime * result + ((termNumber == null) ? 0 : termNumber.hashCode());
		result = prime * result + ((termID == null) ? 0 : termID.hashCode());
		result = prime * result + ((termFullDesc == null) ? 0 : termFullDesc.hashCode());
		return result;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj) { return true; }
		
		if (obj == null) { return false; }
		
		if (getClass() != obj.getClass()) { return false; }
		
		Term other = (Term) obj;
		
		if (endDate == null)  {
			if (other.endDate != null) { return false; }
		} else if (!endDate.equals(other.endDate)) { return false; }
		
		if (shortAcademicYear == null) {
			if (other.shortAcademicYear != null) { return false; }
		} else if (!shortAcademicYear.equals(other.shortAcademicYear)) { return false; }
		
		if (shortTermFullDesc == null)  {
			if (other.shortTermFullDesc != null) { return false; }
		} else if (!shortTermFullDesc.equals(other.shortTermFullDesc)) { return false; }
		
		if (startDate == null) {
			if (other.startDate != null) { return false; }
		} else if (!startDate.equals(other.startDate)) { return false; }
		
		if (termNumber == null)  {
			if (other.termNumber != null) { return false; }
		}  else if (!termNumber.equals(other.termNumber)) { return false; }
		
		if (termID == null) {
			if (other.termID != null) { return false; }
		}  else if (!termID.equals(other.termID)) { return false; }
		
		if (termFullDesc == null) {
			if (other.termFullDesc != null) { return false; }
		} else if (!termFullDesc.equals(other.termFullDesc)) { return false; }
		
		return true;
	}

	public int compareTo(Term another) {
		if (another == null) return 1;
		// sort descending, most recent first
		return another.termID.compareTo(termID);
	}
}
